﻿
@{
    ViewData["Title"] = "栏目匹配";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div class="btn-group-sm" role="group" id="toolbar">
            <a class="btn btn-primary single" onclick="setTemplate(this);" data-id="0" data-role="cms:templatematch:match">
                <i class="fa fa-edit"></i> 设置模板
            </a>

            <a class="btn btn-info" onclick="expandAll();" data-role="0">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="dataTable"></table>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript" src="~/ui/plugins/bootstrap-treetable/bootstrap-treetable.js"></script>
    <script>
        var $table;
        $(function () {
            loadGrid();
        });

        function loadGrid() {
            let options = {
                url: '/Cms/TemplateMatch/MatchList',
                id: 'dataTable',
                code: "Id",
                parentCode: "ParentId",
                uniqueId: "Id",
                toolbar: '#toolbar',
                rootIdValue: 0,
                striped: false,
                expandColumn: 1,
                showSearch: true,
                showRefresh: true,
                showColumns: true,
                expandAll: true,
                expandFirst: true,
                columns: [
                    { field: 'selectItem', radio: true },
                    { field: 'ChannelName', title: '栏目名称', align: 'left', width:'300px'},
                    { field: 'ChannelTemplateName', title: '栏目模板', align: 'left' },
                    { field: 'ContentTemplateName', title: '内容模板', align: 'left' }
                ]
            };
            $table = $("#dataTable").easyTreeTable(options);

        }


        function setTemplate(obj) {
            var rows = $table.easyTreeTable("selected");
            if (rows.length == 0) {
                jutils.warn("请选择数据行");
                return;
            }
            var url = '/cms/TemplateMatch/Match';
            jutils.dialog('匹配模板', url, { channelId: rows[0].Id },null, function () {
                 $table.easyTreeTable('search');
            });
        }

        function expandAll() {
            $table.easyTreeTable('expandAll');
        }
    </script>
}



